import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const actions = {

};

const mutations = {
    changeArticleValue(state, value){
        state.articleValue = value;
    },
    login(state, value){
        if(value === 0){
            state.dialogFormVisible = false
        }else{
            state.dialogFormVisible = true
        }
    },
    changeShow(state, value){
        if(value === 1){
            state.show = true,
            state.dialogFormVisible = false
        }else{
            state.show = false
            localStorage.removeItem('id')
            localStorage.removeItem('img')
            localStorage.removeItem('username')
        }
    },
    userAvatarUrl(state,value){
        state.avatarUrl = value
        localStorage.setItem('img', value)
    },
    setHotArticle(state,value){
        state.hotArticle = value,
        sessionStorage.setItem('hotArticle', JSON.stringify(value))
    }
};

const state = {
    articleValue:'',
    dialogFormVisible:false,
    //用户登录成功/失败
    show:false,
    avatarUrl:'',
    hotArticle:[]
};

const store = new Vuex.Store({
    actions,
    mutations,
    state
})

export default store;
